PATTERN_PATH=/mnt/e/project-pattern/
# 安装
 if [[ -z "$(docker images -q logstash:7.14.0 2> /dev/null)" ]]; then
    docker pull logstash:7.14.0
  else
     echo "logstash installed"
 fi

  if [[ -z "$(docker images -q kibana:7.14.0 2> /dev/null)" ]]; then
    docker pull kibana:7.14.0
  else
     echo "kibana installed"
 fi

#运行 logstash
  if [[ -z "$(docker ps -aqf "name=logstash")" ]]; then
      mkdir -p  /opt/logstash
      \cp -r $PATTERN_PATH/.environment/init/docker/log/logstash.conf /opt/logstash/
      \cp -r $PATTERN_PATH/.environment/init/docker/log/logstash.yml /opt/logstash/
      docker run -d \
          --name=logstash \
          --add-host=project-pattern:192.168.0.101 \
          --privileged=true --restart=always \
          -p 5044:5044 \
          logstash:7.14.0
        docker cp /opt/logstash/logstash.yml logstash:/usr/share/logstash/config/
        docker cp /opt/logstash/logstash.conf logstash:/usr/share/logstash/config/
        docker restart logstash
  else
      echo "logstash running"
  fi

#运行 kibana
  if [[ -z "$(docker ps -aqf "name=kibana")" ]]; then
      mkdir -p  /opt/kibana
      \cp -r $PATTERN_PATH/.environment/init/docker/log/kibana.yml /opt/kibana/
      docker run -d \
          --name=kibana \
          --add-host=project-pattern:192.168.0.101 \
          --privileged=true --restart=always \
          -p 22222:22222 \
          kibana:7.14.0
        docker cp /opt/kibana/kibana.yml kibana:/usr/share/kibana/config/
        docker restart kibana
  else
      echo "logstash running"
  fi